from flask import Flask
# 导入首先查看的是包下__init__文件，由于__init__中已经导入了bp，所以主文件仅从back等包下导入即可，否则需要写成apps.back.views
from apps.back import bp as back_bp
from apps.common import bp as common_bp
from apps.front import bp as front_bp
import config
from exts import db,mail,csrf
# CSRF保护
# from flask_wtf import CSRFProtect

def create_app():
    app = Flask(__name__)
    # app绑定config，获得相关信息
    app.config.from_object(config)

    # 注册蓝图
    app.register_blueprint(back_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)

    db.init_app(app)
    # 初始化mail
    mail.init_app(app)
    # 否则会报错
    # 进行保护
    csrf.init_app(app)
    return app

# 主文件不写URL，将在对应的视图文件中写
if __name__ == '__main__':
    app = create_app()
    app.run(port=8000)
